public class test1 {
    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     int val;
     *     TreeNode left;
     *     TreeNode right;
     *     TreeNode() {}
     *     TreeNode(int val) { this.val = val; }
     *     TreeNode(int val, TreeNode left, TreeNode right) {
     *         this.val = val;
     *         this.left = left;
     *         this.right = right;
     *     }
     * }
     */
    class Solution {
        public int sumNumbers(TreeNode root) {
            return dfs(root,0);
        }
        private int dfs(TreeNode root,int sumNumber){
            if(root==null){
                return 0;
            }
            sumNumber = sumNumber*10 + root.val;
            if(root.left==null && root.right==null){
                //叶子节点
                return sumNumber;
            }
            return dfs(root.left,sumNumber)+dfs(root.right,sumNumber);
        }
    }
}
